package edu.dgut.bbssystem.controller;

import edu.dgut.bbssystem.common.ActionResult;
import edu.dgut.bbssystem.common.Constant;
import edu.dgut.bbssystem.common.PageInfo;
import edu.dgut.bbssystem.pojo.Post;
import edu.dgut.bbssystem.service.PostService;
import edu.dgut.bbssystem.util.BbsUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/post")
//@CrossOrigin
public class PostController {
    @Autowired
    PostService postService;
    @PostMapping("add")
    public ActionResult addPost(HttpSession session, @RequestBody Post post){
        post.setAuthorId(BbsUtils.getUserInSession(session).getUserId());
        int count = postService.addPost(post);
        int code = count==1? Constant.SUCCESS:Constant.FAIL;
        return new ActionResult();
    }
    //这个需要级联删除，现在没空考虑
    @DeleteMapping("delete")
    public ActionResult Post(HttpSession session,int commentId){
      /*  int count = commentService.deleteById(commentId);
        int code = count==1? Constant.SUCCESS:Constant.FAIL;*/
        return new ActionResult();
    }
    @GetMapping("postPage")
    public ActionResult postostPage(int pageNum, int pageSize){
        PageInfo<Post> pageInfo= postService.pageQueryAll(pageNum,pageSize);
        return new ActionResult(Constant.SUCCESS,pageInfo);
    }
}
